package com.bx.implatform.config;


import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Contact;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SwaggerConfig {

    @Bean
    public GroupedOpenApi userApi() {
        String[] paths = {"/**"};
        String[] packagedToMatch = {"com.bx"};
        return GroupedOpenApi.builder().group("IM-Platform")
                .pathsToMatch(paths)
                .packagesToScan(packagedToMatch).build();
    }

    @Bean
    public OpenAPI customOpenAPI() {
        Contact contact = new Contact();
        contact.setName("Blue");
        return new OpenAPI().info(new Info()
                        .title("群聊IM接口文档")
                        .description("群聊IM业务平台服务")
                        .contact(contact)
                        .version("3.0")
                        .termsOfService("https://www.boxim.online")
                        .license(new License().name("MIT")
                                .url("https://www.boxim.online")))
                .addSecurityItem(new SecurityRequirement().addList("Accesstoken"))
                .components(new Components()
                        .addSecuritySchemes("Accesstoken", new SecurityScheme()
                                .type(SecurityScheme.Type.APIKEY)
                                .in(SecurityScheme.In.HEADER)
                                .name("Accesstoken")
                                .description("用户ID：1945296121319706625\n 测试token：eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIxOTQ1Mjk2MTIxMzE5NzA2NjI1IiwiZXhwIjoxNzU4Njc3NzMzLCJpbmZvIjoie1wibmlja05hbWVcIjpcIuW8oOasolwiLFwidGVybWluYWxcIjoyLFwidXNlcklkXCI6XCIxOTQ1Mjk2MTIxMzE5NzA2NjI1XCIsXCJ1c2VyTmFtZVwiOlwiMTk0NTI5NjEyMTMxOTcwNjYyNVwifSJ9.g3P_NxVBF0DDFZzx5IVbJ08TupCCpHin6wm96bSRJTo")));
    }

}
